{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 14 列表"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "1.【选择】下面哪个选项不是定义列表的正确方式？（ ）\n",
    "\n",
    "A.myList1 = [\"a\",\"b\",\"c\",\"d\"]  \n",
    "B.myList2 = list(\"Python\")  \n",
    "C.myList3 = myList2  \n",
    "D.myList4 = 2,3,4,5  "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "答案：D"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "2.【选择】根据下面表达式，a的值是：（ ）  \n",
    "`\n",
    "myList = \"Hello World\"\n",
    "a = myList[3:8]`\n",
    "\n",
    "A.llo W\n",
    "B.llo Wo\n",
    "C.lo Wo\n",
    "D.lo Wor"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "答案：C"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "3.【填空】请写出如何切片myList[]的倒数第3~5位。（ ）"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "答案：myList[-5:-3]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "4.【判断】列表内元素的下标是从0开始的。（ ）\n",
    "\n",
    "A.√  \n",
    "B.×"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "5.【选择】下列Python表达式可以将列表反向并改变原列表值的是：（ ）\n",
    "\n",
    "A.myList[::-1]  \n",
    "B.myList[:-1]  \n",
    "C.reversed(myList1)  \n",
    "D.myList.reverse()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "答案：D"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "6.【填空】下列表达式的结果是：（ ）  \n",
    "`\n",
    "myList1 = [1,2,3,4]\n",
    "myList2 = [10]\n",
    "myList1 = myList1 + myList2\n",
    "myList2.append(myList1)\n",
    "print(myList1)\n",
    "print(myList2)\n",
    "`"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "答案：  \n",
    "[1, 2, 3, 4, 10]\n",
    "[10, [1, 2, 3, 4, 10]]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "7.【填空】请写出下列表达式的结果：（ ）  \n",
    "`\n",
    "[\"第%d个\"%i+\"奇数是：%d\"%(i*2-1) for i in range(1,3)]`"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "答案：['第1个奇数是：1', '第2个奇数是：3']"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "8.【选择】下列表达式的执行结果是：（ ）\n",
    "`\n",
    "lst1 = [3,4,5,6,7,8]\n",
    "lst1.insert(2,3)\n",
    "print(lst1)`\n",
    "\n",
    "A.[3,4,5,3,6,7,8]  \n",
    "B.[3,4,3,5,6,7,8]  \n",
    "C.[3,4,5,6,7,8,[2,3]]  \n",
    "D.[3,4,5,6,7,8,2,3]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "答案：B"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "9.【选择】下列选项中不能把列表中全部“3”删除的是：（ ）    \n",
    "`lst = [2,3,3,4,6,1,3,5,3,2,4]`\n",
    "\n",
    "A.lst.remove(3)  \n",
    "B.\n",
    "`for i in lst:\n",
    "    if i == 3:\n",
    "        lst.remove(i)`  \n",
    "C.[i for i in lst if i != 3]  \n",
    "D.list(set(lst))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "答案：C"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "10.【填空】请写出下列表达式的结果：（ ）  \n",
    "`\n",
    "lst1 = [\"a\",\"b\",\"c\",\"d\"]\n",
    "lst2 = [\"A\",\"B\",\"C\",\"D\"]\n",
    "[i + j for i,j in zip(lst1,lst2)]`\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "答案：['aA', 'bB', 'cC', 'dD']"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
